#!/bin/sh

LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
#GOOGLE=$(ping -4 www.gstatic.com -c 1 -w 5| sed '1{s/[^(]*(//;s/).*//;q}')

#iptables -t nat -I OUTPUT -p tcp -d $GOOGLE -j REDIRECT --to-port 7070

#sleep 3

/usr/bin/wget --spider --quiet --tries=3 --timeout=3 www.gstatic.com/generate_204

if [ "$?" -eq "0" ]; then
	echo '['$LOGTIME'] ShadowsocksR No Problem.'
else
	/usr/bin/wget --spider --quiet --tries=3 --timeout=3 www.baidu.com
	if [ "$?" -eq "0" ]; then
		echo '['$LOGTIME'] Problem decteted, restarting ShadowsocksR...'
		/etc/init.d/ssrpro restart
	else
		echo '['$LOGTIME'] Network Problem. Do nothing.'
	fi
fi

#sleep 3

#iptables -t nat -D OUTPUT -p tcp -d $GOOGLE -j REDIRECT --to-port 7070









